<%@ page import="java.sql.*"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'Mysql.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>
<body>
	<%
		request.setCharacterEncoding("utf-8");
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/school";
			Connection con = DriverManager.getConnection(url, "root", "1234");
			String sql = "INSERT INTO student (sname,sex,telephone,qq,wechat,gradeid,enterdate,fromcity,birthday,address,pass) VALUES (?,?,?,?,?,?,?,?,?,?,?) ";
			PreparedStatement ps = con.prepareStatement(sql);
			String name = request.getParameter("sname");
			String sex = request.getParameter("sex");
			String telephone = request.getParameter("telephone");
			String qq = request.getParameter("qq");
			String wechat = request.getParameter("wechat");
			String gradeid = request.getParameter("gradeid");
			String enterdate = request.getParameter("enterdate");
			String fromcity = request.getParameter("fromcity");
			String birthday = request.getParameter("birthday");
			String address = request.getParameter("address");
			String pass = request.getParameter("pass");

			ps.setString(1, name);
			ps.setString(2, sex);
			ps.setString(3, telephone);
			ps.setString(4, qq);
			ps.setString(5, wechat);
			ps.setString(6, gradeid);
			ps.setString(7, enterdate);
			ps.setString(8, fromcity);
			ps.setString(9, birthday);
			ps.setString(10, address);
			ps.setString(11, pass);

			ps.executeUpdate();
			out.print("添加成功");
			ps.close();
			con.close();
		} catch (Exception e) {
			out.print(e);
		}
	%>
	
</body>
</html>
